#ifndef __MEMORY_POOL__
#define __MEMORY_POOL__
#include <cstl/common.h>

/**
* Using a typedef here to "hide" the implementation details of the memory pool.
* It is a pointer and its content is in the C file.
*/
typedef struct mempool* mempool_t;

/**
* Allocate memory and initialze a mempool object through its pointer.
* if failed, the pool point to null.
*/
void mempool_init(IN OUT mempool_t* pool);

/**
* Destroy a mempool object and free its memory through its pointer.
*/
void mempool_destroy(mempool_t* pool);

/**
* Allocate memory through special memory pool obj.
* @param pool memory pool object.
* @param {size_t} n memory size want to get.
* @return memory allocated, if failed it will be null.
*/
void* mempool_malloc(mempool_t pool, size_t n);

/**
* Free memory which is dynamic allocated and restore it into special memory pool.
*/
void mempool_free(mempool_t pool, void* mem, size_t n);


/**
* Encapsulate of default malloc and free for detecting memory leak.
* @{
*/
// #define __malloc __sys_malloc
// #define __free __sys_free
// #define __calloc __sys_calloc
#define __memoryleak __sys_leak_num()

void* __sys_malloc(unsigned int size);
void* __sys_calloc(unsigned int size);
void __sys_free(void* mem);
int __sys_leak_num(void);
/* @} */

#endif

